/*
用于电脑端显示浏览审批流量时候的图片的显示
*/
new Vue({
    el: "#container",
    data() {
        return {
            bizId:null,
            bizTable:null,
            fileDatas:[],
        }
    },
    // 在模板渲染成html前调用
    created() {
    },
    // 在模板渲染成html后调用，通常是初始化页面完成后，再对html的dom节点进行一些需要的操作
    mounted() {
        this.bizId = $('#bizId').val();
        this.bizTable = $('#bizType').val();
        this.loadFile();
    },
    methods: {
        loadFile(){
            var that = this;
            $.ajax({
                url:'/file/list',
                type: 'post',
                dataType: 'json',
                data:{
                    bizId:that.bizId,
                    bizTable:that.bizTable
                },
                timeout: 30000,
                success: function(res) {
                    if (res.code == 0 && res.data != null) {
                        // 存在文件
                        let resDatas = res.data;
                        let tFiles = [];
                        $.each(resDatas,function (i, fileData) {
                            let fid = fileData.id;
                            let fileName = fileData.fileName;
                            let isImage = false;
                            let url = "/file/down/" + fid;;
                            // 预览图
                            let preUrl = null;
                            if(isAssetTypeAnImage(fileName)){
                                // 是图片,预览图
                                preUrl = "/file/preview/" + fid;
                                isImage = true;
                            }else {
                                // 不是图片
                                isImage = false;
                            }
                            let showData = {
                                id:fid,
                                fileName:fileName,
                                url:url,
                                preUrl:preUrl,
                                isImage:isImage
                            }
                            tFiles.push(showData);
                        });
                        that.fileDatas = tFiles;
                    } else {

                    }
                },
                error: function(res) {
                    return;
                },
                complete: function(XMLHttpRequest, status) {
                    if(status == 'timeout') {
                        return;
                    }

                }
            })
        },
        /**
         * 显示文档文件
         * @param file
         */
        showDocFile(fid,fname){
            var that = this;
            if(isNull(fid)){
                that.$toast({
                    duration: 3000,
                    message: "请选择文件!"
                });
                return;
            }
            /*previewOAFile(fid,fname);*/
            let url = "/file/down/" + fid;
            window.location.href = url;
        },
    }
})
